//
//  BKShangShiViewModel.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/6/2.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKShangShiViewModel.h"
#import <AFNetworking.h>
@implementation BKShangShiViewModel

+ (void)shangshiWithParams:(NSDictionary *)params success:(void (^)(NSDictionary *))success failure:(void (^)(NSString *))failure{

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/mobile/shangshi3"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSDictionary *data = responseDic[@"extraData"][@"info"];
                 if ([data isKindOfClass:[NSDictionary class]]) {
                      success(data);
                 }else{
                 
                     failure(@"没有了");
                 }
                 
                
                 
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];
    

}




+ (void)getColleageWithSuozaidi:(NSString *)suozaidi pici:(NSString *)pici success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];

    NSDictionary *provDic =  @{
                               @"北京":@"1",
                                @"天津":@"2",
                                @"上海":@"3",
                                @"重庆":@"4",
                                @"河北":@"5",
                                @"河南":@"6",
                                @"山东":@"7",
                                @"山西":@"8",
                                @"安徽":@"9",
                                @"江西":@"10",
                                @"江苏":@"11",
                                @"浙江":@"12",
                                @"湖北":@"13",
                                @"湖南":@"14",
                                @"广东":@"15",
                                @"广西":@"16",
                                @"云南":@"17",
                                @"贵州":@"18",
                                @"四川":@"19",
                                @"陕西":@"20",
                                @"青海":@"21",
                                @"宁夏":@"22",
                                @"黑龙江":@"23",
                                @"吉林":@"24",
                                @"辽宁":@"25",
                                @"西藏":@"26",
                                @"新疆":@"27",
                                @"内蒙古":@"28",
                                @"海南":@"29",
                                @"福建":@"30",
                                @"甘肃":@"31"};
    NSDictionary *piciDic = @{@"提前批":@"5",
                              @"本科一批":@"11",
                              @"本科二批":@"12",
                              @"本科三批":@"13",
                              @"高职专科":@"20"};
    if ([suozaidi length] != 0) {
        params[@"dq"] = provDic[suozaidi];
    }
    if ([pici length] != 0) {
        params[@"pc"] = piciDic[pici];
    }
    
    
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/mobile/xycollege"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSArray *data = responseDic[@"extraData"];
                 if ([data count] != 0) {
                     success(data);
                 }else{
                     
                     failure(@"没有学校");
                 }
                 
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];
}

+ (void)shangshiWithColleageCid:(NSString *)cid fenlei:(NSString *)fenlei zhiwei:(NSString *)zhiwei xueli:(NSString *)xueli page:(NSString *)page len:(NSString *)len success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure
{
    if (page == nil) {
        page = @"1";
    }
    if (len == nil) {
        len = @"20";
    }
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"cid"] = cid;
    params[@"fl"] = fenlei;
    params[@"zw"] = zhiwei;
    params[@"xl"] = xueli;
    params[@"page"] = page;
    params[@"len"] = len;
    
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/mobile/shangshi5"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSArray *data = responseDic[@"extraData"][@"info"];
                 if ([data count] != 0) {
                     success(data);
                 }else{
                     
                     failure(@"没有找到匹配的校友");
                 }
                 
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];
}




@end
